package IntersectionAndUnion;

/**
 * @author ：wang-ting
 * @Date：2025/6/2 19:59
 */
import java.util.ArrayList;
import java.util.Scanner;
public class TestIntersectionAndUnion {
    public static void main(String[] args) {
        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
        Scanner input = new Scanner(System.in);
        int n;
        n = input.nextInt();
        for(int i=1;i<=n;i++)
            list1.add(input.nextInt());
        n = input.nextInt();
        for(int i=1;i<=n;i++)
            list2.add(input.nextInt());
        ArrayList<Integer> list3
                = IntersectionAndUnion.intersection(list1,list2);
        ArrayList<Integer> list4
                = IntersectionAndUnion.union(list1,list2);
        System.out.println("intersection:");
        System.out.println(list3.toString());
        System.out.println("union:");
        System.out.println(list4.toString());
    }
}
